
/**
*塔放js
*/ 

var	towerMounteDS;
var formPanel;
function doTowerMounteDelete(id)
{
	Ext.MessageBox.confirm('确认删除', '确认删除该信息?', 
	function(btn) {
		if(btn == 'yes') // 选中了是按钮	
		{
			JMagnifierWeb.deleteMagnifier(id,function(data)
			{
				if(data)
				{ 
					Ext.Msg.alert('成功',"操作成功！"); 
					towerMounteDS.load({params:{start:0,limit:17,'<%=Constant.BTS_CODE%>':'<%=strbtscode%>'}});	 
					formPanel.getForm().reset();			
				}else
				{
					Ext.Msg.alert("失败","操作失败!");
				}
			})
		}
	})	
}


Ext.onReady(function(){  
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';

	var towerMounteType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'btscode', type: "string"},
							   {name: 'btsname', type: "string"},
							   {name: 'type', type: "string"},
							   {name: 'capacity', type: "string"},
							   {name: 'manufacturer', type: "string"},
							   {name: 'num', type: "string"},
							   {name: 'cellU', type: "string"},
							   {name: 'opentime', type: 'date'},
							   {name: 'refreshtime', type: 'date'},
							   {name: 'maintenance',  type: 'string'},
							   {name: 'memo',  type: 'string'}
						 ]);
	var towerMounteCM = new Ext.grid.ColumnModel(
			[
				new Ext.grid.CheckboxSelectionModel({singleSelect: true}), 	            
				{header: "流水号", sortable: true, dataIndex: 'id',align:'left'},
				{header: "基站编号", sortable: true, dataIndex: 'btscode',align:'left'},
				{header: "基站名称",  sortable: true, dataIndex: 'btsname',align:'left'},	
				{header: "型号",  sortable: true, dataIndex: 'type',align:'left'},	
				{header: "容量",  sortable: true, dataIndex: 'capacity',align:'left'},	
				{header: "厂家",  sortable: true, dataIndex: 'manufacturer',align:'left'},	
				{header: "数量",  sortable: true, dataIndex: 'num',align:'left'},	
				{header: "使用小区", sortable: true, dataIndex: 'cellU',align:'left'},
				{header: "启用日期",  width: 150,sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d'),dataIndex: 'opentime',align:'left'} 				
			]
		);				 
	
	function showDelete(id)
	{
		return "<input type='button' value='删除' class='x-btn button' onclick='doTowerMounteDelete(\"" + id  +   "\")'>";  
	}
	
	
	
	towerMounteDS = new Ext.data.Store({
				proxy: new Ext.data.DWRProxy(JMagnifierWeb.getMagnifierList, true),	
				reader: new Ext.data.ListRangeReader({
					totalProperty: 'totalSize',
					id: 'id'
				}, towerMounteType),
				sortInfo:{field:'id', direction:'ASC'}// 排序信息
			});

	
	var towerMountedGridDiv = Ext.get("mainTabPanelDIV");
	var towerMountedGrid = new Ext.grid.GridPanel({			 	
			ds: towerMounteDS,
			cm: towerMounteCM, 
			sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) {
                            formPanel.getForm().loadRecord(rec);
                        }
                    }
                }),
			autoWidth : true,  
			autoScroll : true,  
			autoHeight　: false,
			region : 'center',
			height: 400,
			minSize: 200,		
			frame:true,
			collapsible:false, 
			enableDragDrop:false, 		
			bbar: new Ext.PagingToolbar({
					pageSize: 17,
					store: towerMounteDS,
					displayInfo: true,
					displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
					emptyMsg: "没有记录"
				})
		});

	towerMounteDS.on('load', function() {
		towerMountedGrid.getSelectionModel().selectFirstRow(); 
	});	

	// Setup the form panel
	formPanel = new Ext.form.FormPanel({
		region     : 'south', 
		bodyStyle  : 'padding: 10px; background-color: #DFE8F6',
		labelWidth : 130,  
		height: 180,
		minSize: 200,
		maxSize: 200,
		frame:true,
		buttonAlign:'right',
		layout:'column', 
		items:[
			 {
				columnWidth:.33,
				layout: 'form',  
				labelWidth:70,	
				labelAlign:'right',			
				items: [
					{
						xtype:'hidden',
						fieldLabel: '流水号',
						width:150,
						name: 'id'
					}, {
						xtype:'textfield',
						readOnly: true,
						fieldLabel: '基站编号',
						//value:'<%=strbtscode%>',
						width:150,
						disabled:true,
						name: 'btscode'
					}, {
						xtype:'textfield',
						fieldLabel: '基站名称',
						width:150,
						name: 'btsname',
						allowBlank:false,
						disabled:true,
						blankText :'请输入基站名称'	
					}, {
						xtype:'numberfield',
						fieldLabel: '容量',
						width:150,
						name: 'capacity',
						value:1,
						allowBlank:false,
						disabled:true,
						blankText :'请输入数量'	
					}, {
						xtype:'numberfield',
						fieldLabel: '数量',
						width:150,
						name: 'num',
						value:1,
						disabled:true,
						allowBlank:false,
						blankText :'请输入容量'	
					}]
			 },
			 {
				columnWidth:.33,
				layout: 'form',  
				labelAlign:'right',	
				labelWidth:70,	 
				items: [
					{
						xtype:'textfield',
						fieldLabel: '规格型号',
						width:150,
						disabled:true,
						name: 'type'
					}, {
						xtype:'textfield',
						fieldLabel: '厂家',
						width:150,
						disabled:true,
						name: 'manufacturer'
					}, {
						xtype:'textfield',
						fieldLabel: '更换及维修记录',
						width:150,
						disabled:true,
						name: 'maintenance'
					}]
			 },
			 {
				columnWidth:.33,
				layout: 'form',  
				labelAlign:'right',	
				labelWidth:70,	 
				items: [
					{
						xtype:'textfield',
						fieldLabel: '使用小区',
						width:150,
						disabled:true,
						name: 'cellU'
					}, {
						xtype:'datefield',
						fieldLabel: '启用日期',
						format : "Y-m-d",
						width:150,
						disabled:true,
						allowBlank:false,
						name: 'opentime'
					}, {
						xtype:'textarea',
						fieldLabel: '备注',
						width:150,
						disabled:true,
						name: 'memo'
					}]
			 }
			] 	
	});



	//Simple 'border layout' panel to house both grids
	
	var displayPanel = new Ext.Panel({
		width    : towerMountedGridDiv.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'TowerMountedTab',
		items    : [
			towerMountedGrid,
			formPanel
		]
	});
	
	
	function saveMagnifier()
	{
		if (!formPanel.getForm().isValid())
			return;	
			
		var form = formPanel.getForm().getValues(false);	
		MagnifierBO = {};
		MagnifierBO.id = form.id;
		MagnifierBO.btscode = form.btscode;
		MagnifierBO.btsname= form.btsname;
		MagnifierBO.type = form.type;
		MagnifierBO.capacity = form.capacity;
		MagnifierBO.manufacturer = form.manufacturer;
		MagnifierBO.num = form.num;
		MagnifierBO.cellU = form.cellU;
		
		MagnifierBO.maintenance = form.maintenance;
		MagnifierBO.memo = form.memo;
		 	
		var opentimeDate = new Date();	
		var arrPlanTime = form.opentime.split("-");		
				
		var yearOth = arrPlanTime[0];
		var monthOth = arrPlanTime[1];
		var dayOth = arrPlanTime[2];
		opentimeDate.setFullYear(yearOth,monthOth-1,dayOth);
		
		
		MagnifierBO.opentime = opentimeDate;
		
			
		JMagnifierWeb.saveMagnifier(MagnifierBO,function(data)
		{
			if(data)
			{ 
				Ext.Msg.alert('成功',"操作成功！"); 
				loadDate(towerMounteDS,formPanel);	 
			}else
			{
				Ext.Msg.alert("失败","操作失败!");
			}
		})
			
	}
	
	loadDate(towerMounteDS,formPanel);
		
	
})